package com.tgy.JUC.BlockingQueueDemo;

import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.concurrent.ArrayBlockingQueue;

/***
 * @ClassName: Test2
 * @Description: 有返回值，不抛出异常
 * @Auther: 送你一块二向箔
 * @Date: 17:26 2022/3/11
 * @version : V1.0
 */
public class Test2 {
    public static void main(String[] args) {
        run1();
        run2();
    }

    //多放了会返回false
    public static void run1(){
        ArrayBlockingQueue<String> strings = new ArrayBlockingQueue<>(3);
        System.out.println(strings.offer("a"));
        System.out.println(strings.offer("b"));
        System.out.println(strings.offer("c"));
        System.out.println(strings.element());
        System.out.println(strings.peek());
        //超出范围异常IllegalStateException
        System.out.println(strings.offer("d"));
    }

    //多取了 会返回null
    public static void run2(){
        ArrayBlockingQueue<String> strings = new ArrayBlockingQueue<>(1);
        System.out.println(strings.offer("a"));
        System.out.println(strings.poll());
        System.out.println(strings.poll());

    }
}
